package com.example.demo.practice.monitoring;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

import com.example.demo.practice.R;
import com.example.demo.practice.innerclass.IBaseActivity;

public class VideoPlay extends IBaseActivity {
    private ImageView sta1;
    private ImageView sta2;
    private ImageView sta3;
    private ImageView sta4;
    private ImageView sta5;
    private TextView tx1;
    private TextView tx2;
    private TextView tx3;
    private TextView tx4;
    private TextView tx5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_play);
        Intent intent = getIntent();

        String code = intent.getStringExtra("code");
        setTitle("视频" + code);

        sta1 = (ImageView) findViewById(R.id.sta1);
        sta2 = (ImageView) findViewById(R.id.sta2);
        sta3 = (ImageView) findViewById(R.id.sta3);
        sta4 = (ImageView) findViewById(R.id.sta4);
        sta5 = (ImageView) findViewById(R.id.sta5);
        tx1 = (TextView) findViewById(R.id.tx1);
        tx2 = (TextView) findViewById(R.id.tx2);
        tx3 = (TextView) findViewById(R.id.tx3);
        tx4 = (TextView) findViewById(R.id.tx4);
        tx5 = (TextView) findViewById(R.id.tx5);

        String company = intent.getStringExtra("company");
        String address = intent.getStringExtra("address");
        TextView textView2 = (TextView) findViewById(R.id.name);
        textView2.setText(company);
        TextView textView3 = (TextView) findViewById(R.id.address);
        textView3.setText(address);
        tx1.setText("        1楼大厅" + "        编号：" + code);
        tx2.setText("        2楼大厅" + "        编号：" + code);
        tx3.setText("        3楼大厅" + "        编号：" + code);
        tx4.setText("        4楼大厅" + "        编号：" + code);
        tx5.setText("        5楼大厅" + "        编号：" + code);

        tx1.setOnClickListener(new TextView.OnClickListener(){//创建监听
            public void onClick(View v) {
                returns();
                change(tx1,sta1);
                plays(1);
            }
        });
        tx2.setOnClickListener(new TextView.OnClickListener(){//创建监听
            public void onClick(View v) {
                returns();
                change(tx2,sta2);
                plays(2);
            }
        });
        tx3.setOnClickListener(new TextView.OnClickListener(){//创建监听
            public void onClick(View v) {
                returns();
                change(tx3,sta3);
                plays(1);
            }
        });
        tx4.setOnClickListener(new TextView.OnClickListener(){//创建监听
            public void onClick(View v) {
                returns();
                change(tx4,sta4);
                plays(2);
            }
        });
        tx5.setOnClickListener(new TextView.OnClickListener(){//创建监听
            public void onClick(View v) {
                returns();
                change(tx5,sta5);
                plays(1);
            }
        });
        sta1.setOnClickListener(new TextView.OnClickListener(){//创建监听
            public void onClick(View v) {
                returns();
                change(tx1,sta1);
                plays(1);
            }
        });
        sta2.setOnClickListener(new TextView.OnClickListener(){//创建监听
            public void onClick(View v) {
                returns();
                change(tx2,sta2);
                plays(2);
            }
        });
        sta3.setOnClickListener(new TextView.OnClickListener(){//创建监听
            public void onClick(View v) {
                returns();
                change(tx3,sta3);
                plays(1);
            }
        });
        sta4.setOnClickListener(new TextView.OnClickListener(){//创建监听
            public void onClick(View v) {
                returns();
                change(tx4,sta4);
                plays(2);
            }
        });
        sta5.setOnClickListener(new TextView.OnClickListener(){//创建监听
            public void onClick(View v) {
                returns();
                change(tx5,sta5);
                plays(1);
            }
        });

        plays(1);

    }

    public void plays(int num){
        String url = "http://192.168.101.50:8081/videoPlay?name=" + num;
        Uri uri = Uri.parse(url);
        VideoView videoView = (VideoView) findViewById(R.id.videoView);

        videoView.setMediaController(new MediaController(this));
        videoView.setVideoURI(uri);
        //让videoView获得焦点
        videoView.requestFocus();
        videoView.start();
    }

    public void change(TextView texts,ImageView statues){
        texts.setTextColor(this.getResources().getColor(R.color.white));
        statues.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(),R.drawable.sl));
    }

    public void returns(){
        tx1.setTextColor(this.getResources().getColor(R.color.negativeTextColor));
        tx2.setTextColor(this.getResources().getColor(R.color.negativeTextColor));
        tx3.setTextColor(this.getResources().getColor(R.color.negativeTextColor));
        tx4.setTextColor(this.getResources().getColor(R.color.negativeTextColor));
        tx5.setTextColor(this.getResources().getColor(R.color.negativeTextColor));
        sta1.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(),R.drawable.unsl));
        sta2.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(),R.drawable.unsl));
        sta3.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(),R.drawable.unsl));
        sta4.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(),R.drawable.unsl));
        sta5.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(),R.drawable.unsl));
    }
}
